package com.wy.projectssj.service.impl;

import com.wy.projectssj.dao.RoleDao;
import com.wy.projectssj.dao.UserRoleDao;
import com.wy.projectssj.domain.Role;
import com.wy.projectssj.service.RoleService;
import com.wy.projectssj.utils.Uuid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * @Author: wy
 * @Date:2019/8/29 9:08
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
     private RoleDao roleDao;
    @Autowired
     private UserRoleDao userRoleDao;
    @Override
    public List<Role> findAll() {

        return roleDao.findAll();
    }

    @Override
    public int save(Role role) {
         role.setId(Uuid.getUuid());
        return roleDao.save(role);
    }

    @Override
    public int deleteRole(String[] ids) {
        /*在删除主表信息之前,先把中间表关联的信息删除*/
        int result=-1;
        if(ids!=null&&ids.length>0) {
            userRoleDao.deleteByIds(ids);
            result = roleDao.delete(ids);
        }
        return  result;
    }


}
